package com.nc.delivery_project.server.domain.path_finder.graph;

/**
 * Created by Даниил on 04.02.2015.
 */
public class Edge {
    public static final int TIME_WEIGHT_MODE = 1;
    public static final int COST_WEIGHT_MODE = 2;
    public static int WEIGHT_MODE = -1;

    private final Node source;
    private final Node destination;
    private final double time;
    private final double cost;

    public Edge(Node source, Node destination, double time, double cost) {
        this.source = source;
        this.destination = destination;
        this.time = time;
        this.cost = cost;
    }

    public Node getDestination() {
        return destination;
    }

    public Node getSource() {
        return source;
    }
    public double getWeight() {
        switch (WEIGHT_MODE) {
            case TIME_WEIGHT_MODE:
                return time;
            case COST_WEIGHT_MODE:
                return cost;
            default: throw new RuntimeException("you must set weight mode");
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Edge)) return false;

        Edge edge = (Edge) o;

        if (Double.compare(edge.cost, cost) != 0) return false;
        if (Double.compare(edge.time, time) != 0) return false;
        if (!destination.equals(edge.destination)) return false;
        if (!source.equals(edge.source)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = source.hashCode();
        result = 31 * result + destination.hashCode();
        temp = Double.doubleToLongBits(time);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(cost);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Edge{");
        sb.append("source=").append(source);
        sb.append(", destination=").append(destination);
        sb.append(", time=").append(time);
        sb.append(", cost=").append(cost);
        sb.append('}');
        return sb.toString();
    }
}
